//
//  YJDNaviBar.m
//  YJDSDK
//
//  Created by skyline on 2018/3/9.
//  Copyright © 2018年 skyline. All rights reserved.
//

#import "YJDNaviBar.h"
@interface YJDNaviBar()
@property (nonatomic, strong) YJDCustomButton *backBtn;
@property (nonatomic, strong) YJDLabel *titleLBL;
@property (nonatomic, strong) UIView *line;
@end
@implementation YJDNaviBar
- (instancetype)init
{
    self = [super init];
    if (self)
    {
        self.backBtn.hidden = NO;
        self.line.hidden = NO;
        self.backgroundColor = [UIColor whiteColor];
    }
    return self;
}

- (YJDCustomButton *)backBtn
{
    if (!_backBtn)
    {
        _backBtn = [[YJDCustomButton alloc]initWithBackIMG:@"back"];
        [_backBtn addTarget:self action:@selector(yjd_actionForBackButton) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:_backBtn];
        [_backBtn mas_makeConstraints:^(SK_MASConstraintMaker *make) {
            make.left.equalTo(self).with.offset(5);
            make.top.equalTo(self).with.offset(5);
            make.size.mas_equalTo(CGSizeMake(BUTTONHEIGHT - 14, BUTTONHEIGHT - 14));
        }];
    }
    return _backBtn;
}

- (YJDLabel *)titleLBL
{
    if (!_titleLBL)
    {
        _titleLBL = [[YJDLabel alloc] init];
        _titleLBL.font = [UIFont systemFontOfSize:15];
        _titleLBL.textColor = TEXT_BLACK_COLOR;
        [self addSubview:_titleLBL];
        [_titleLBL mas_makeConstraints:^(SK_MASConstraintMaker *make) {
            make.center.equalTo(self);
        }];
    }
    return _titleLBL;
}

- (UIView *)line
{
    if (!_line)
    {
        _line = [[UIView alloc] init];
        _line.backgroundColor = CELL_LINE_COLOR;
        [self addSubview:_line];
        [_line mas_makeConstraints:^(SK_MASConstraintMaker *make) {
            make.left.equalTo(self);
            make.right.equalTo(self);
            make.bottom.equalTo(self.mas_bottom);
            make.height.mas_equalTo(1);
        }];
    }
    return _line;
}

- (void)setTitle:(NSString *)title
{
    if (_title != title)
    {
        _title = title;
        self.titleLBL.text = _title;
    }
}

- (void)yjd_actionForBackButton
{
    if (self.delegate && [self.delegate respondsToSelector:@selector(yjd_methodForNaviBarDelegate)])
    {
        [self.delegate yjd_methodForNaviBarDelegate];
    }
}

/*
 // Only override drawRect: if you perform custom drawing.
 // An empty implementation adversely affects performance during animation.
 - (void)drawRect:(CGRect)rect {
 // Drawing code
 }
 */

@end
